#!/bin/bash
set -e
echo 'GTK_IM_MODULE=fcitx
QT_IM_MODULES=wayland;fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
SDL_IM_MODULE=fcitx
GLFW_IM_MODULE=ibus' >> /etc/environment
# cp /etc/pacman.conf /etc/pacman.conf.backup
systemctl enable --now grub-btrfsd.service
# pacman -S --needed virtualbox virtualbox-host-modules-arch virtualbox-guest-iso && modprobe vboxdrv
# gpasswd -a h vboxusers
echo 'tcp_bbr' > /etc/modules-load.d/user.conf
modprobe tcp_bbr
echo 'net.core.default_qdisc = cake
net.ipv4.tcp_congestion_control = bbr
kernel.sysrq = 1
net.ipv4.ip_forward = 1
net.ipv4.conf.all.forwarding = 1
net.ipv6.conf.all.forwarding = 1
#net.core.netdev_max_backlog = 16384
#net.core.somaxconn = 8192
#net.ipv4.tcp_fastopen = 3
#net.ipv4.tcp_max_syn_backlog = 8192
#net.ipv4.tcp_max_tw_buckets = 2000000
#net.ipv4.tcp_tw_reuse = 1
#net.ipv4.tcp_fin_timeout = 10
#net.ipv4.tcp_slow_start_after_idle = 0
#net.ipv4.tcp_keepalive_time = 60
#net.ipv4.tcp_keepalive_intvl = 10
#net.ipv4.tcp_keepalive_probes = 6
#net.ipv4.tcp_sack = 1' > /etc/sysctl.d/99-sysctl.conf
sysctl --system

# echo '# HDD
# ACTION=="add|change", KERNEL=="sd[a-z]*", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq"
#
# # SSD
# ACTION=="add|change", KERNEL=="sd[a-z]*|mmcblk[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="bfq"
#
# # NVMe SSD
# ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="none"' > /etc/udev/rules.d/60-ioschedulers.rules
# udevadm control --reload
# udevadm trigger
# grep "" /sys/block/*/queue/scheduler

echo 'set show-all-if-ambiguous on
# Color files by types
# Note that this may cause completion text blink in some terminals (e.g. xterm).
set colored-stats On
# Append char to indicate type
set visible-stats On
# Mark symlinked directories
set mark-symlinked-directories On
# Color the common prefix
set colored-completion-prefix On
# Color the common prefix in menu-complete
set menu-complete-display-prefix On
set completion-ignore-case on' > ~/.inputrc

# sed -i 's/#zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
# sed -i 's/#zh_CN.GB18030 GB18030/zh_CN.GB18030 GB18030/g' /etc/locale.gen
# sed -i 's/#zh_CN.GBK GBK/zh_CN.GBK GBK/g' /etc/locale.gen
# sed -i 's/#zh_CN GB2312/zh_CN GB2312/g' /etc/locale.gen
# locale-gen

echo '[Service]
ExecStart=/usr/bin/mkdir /sys/fs/cgroup/proxy.slice
[Unit]
Before=iptables.service
Before=ip6tables.service
[Install]
WantedBy=multi-user.target' > /etc/systemd/system/my_proxy.service
sudo systemctl enable --now my_proxy.service
